<%@ page import="com.example.pojo.Ent" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>系统首页</title>
  <script type="text/javascript" src="./static/jquery.min.js"></script>
  <script type="text/javascript">
    function edit(event){
      var box = document.getElementById("box");
      box.style.display="block"
      document.getElementById("uid").value=event
    }
    function sub1(){
      var box = document.getElementById("box");
      box.style.display="none"
    }
    function sub(){
      var id = document.getElementById("uid").value;
      var name = document.getElementById("name").value;
      var workingLife = document.getElementById("workingLife").value;
      // var workExperience = document.getElementById("workExperience").value;
      var personalProfile = document.getElementById("personalProfile").value;
      // var departmentId = document.getElementById("departmentId").value;
      var graduateSchool = document.getElementById("graduateSchool").value;
      console.log(id,name,workingLife,personalProfile,graduateSchool)
      $.ajax({
        url: 'http://localhost:8080/ent?action=EntEdit',
        type: 'post',
        data: {
          id:id,
          name1:name,
          workingLife1:workingLife,
          personalProfile:personalProfile,
          graduateSchool:graduateSchool
        },
        dataType: 'json',
        success:(data)=>{
          console.log(data)
          if (data.zt=200){
            location.reload()
          }
        }
      })
    }
    function del(event) {
      $.ajax({
        url: 'http://localhost:8080/ent?action=EntDel',
        type: 'post',
        data: {id: event},
        dataType: 'json',
        success: (data) => {
          if (data.zt==200){
            location.reload()
          }
        }, error: (err) => {
          console.log(err)
        }
      })
    }
  </script>
  <style>
    #btn {
      width: 100px;
      padding: 5px;
      color: white;
      background-color: #9b9b3f;
      border: 1px solid #ffffff;
      border-radius: 5px;
      margin: 10px;
    }
    table td{
      padding:5px 20px;
    }
    #bigBox{
      width:100%;
      background-image: url("static/背景3.png");
      background-repeat: no-repeat;
      background-size: 100%;
    }
  </style>
</head>
<body>
<div id="bigBox" style="background-color: #9d7474;height: 870px;box-sizing: border-box;padding: 30px">
<%--  <h1 style="text-align: center;color: white">商品信息表</h1>--%>
  <button id="btn"><a href="./add.jsp" style="text-decoration: none;color: white;font-size: 18px;font-weight: bolder;">新增</a></button>



  <div  style="display: flex;">
    <table  border="1px" STYLE="text-align: center;padding:20px;background-color: #05a8ef;color: white;border-radius: 10px">
      <td style="background-color: #382b2b">Name</td>
      <td style="background-color: #382b2b">Count</td>
      <td style="background-color: #382b2b">PurchasePrice</td>
      <td style="background-color: #382b2b">SellingPrice</td>
      <td style="background-color: #382b2b">Operation</td>
      <%
        List<Ent> students = (List<Ent>) request.getAttribute("entAll");
        for (Ent ent : students) { %>
      <tr>
        <td><%=ent.getName()%>
        </td>
        <td><%=ent.getWorkingLife()%>
        </td>
        <td><%=ent.getPersonalProfile()%>
        </td>
        <td><%=ent.getGraduateSchool()%>
        </td>
        <td><button style="font-size:20px;background-color: #05a8ef;color: white" onclick="edit(<%=ent.getId()%>)">修改</button>
          <button style="font-size:20px;background-color: #b72d2d;color: white" onclick="del(<%=ent.getId()%>)">删除</button></td>
      </tr>
      <% } %>
    </table>
    <div id="box" style="border: 1px solid black;width: 400px;display: none;text-align: center;padding: 10px;margin-left: 30px;border-radius: 20px;background-color: #05a8ef">
      <h1 style="color: white">修改</h1>
      <table>
        <tr>
          <td style="color: white">ID：</td>
          <td><input type="text" id="uid" name="id" value="默认0" disabled></td>
        </tr>
        <tr>
          <td style="color: white">Name：</td>
          <td><input type="text" id="name" name="name" placeholder="请输入商品名"></td>
        </tr>
        <tr>
          <td style="color: white">Count：</td>
          <td><input type="text" id="workingLife" name="workingLife" placeholder="请输入商品库存"></td>
        </tr>
        <tr>
          <td style="color: white">PurchasePrice：</td>
          <td><input type="text" id="personalProfile" name="personalProfile" placeholder="请输入商品进价"></td>
        </tr>
        <tr>
          <td style="color: white">SellingPrice：</td>
          <td><input type="text" id="graduateSchool" name="graduateSchool" placeholder="请输入商品售价"></td>
        </tr>
      </table>
      <button onclick="sub()" style="font-size:20px;margin: 5px;background-color: #05a8ef;color: white">确认修改</button>
      <button onclick="sub1()" style="font-size:20px; margin: 5px;background-color: #c94c4c;color: white">取消</button>
    </div>
  </div>

</div>

</body>
</html>
